$(function () {
    page();
})

function page() {
    $.post("/Mmanufacture.do/WZYmManufactureAddCha",{productname:$("#productname").val()}, function (sdata) {
        let str = "     <tr class=\"table-success\">\n" +
            "            <th>点选</th>\n" +
            "            <th>生产计划编号</th>\n" +
            "            <th>产品编号</th>\n" +
            "            <th>产品名称</th>\n" +
            "            <th>描述</th>\n" +
            "            <th>数量</th>\n" +
            "            <th>出库编号集合</th>\n" +
            "            <th>审核时间</th>\n" +
            "        </tr>\n";
        $.each(sdata, function (index, item) {
            let dui =JSON.stringify(item);
            str += "     <tr >\n" +
                "            <td><input type='checkbox' class='productid' style='width: 20px;height: 20px;' value='" + dui + "'></td>\n" +
                "            <td>" + item.applyid + "</td>\n" +
                "            <td><a href='#' onclick=\"chaDF('" + item.productid + "')\">" + item.productid + "</a></td>\n" +
                "            <td>" + item.productname + "</td>\n" +
                "            <td>" + item.productdescribe + "</td>\n" +
                "            <td>" + item.amount + "</td>\n" +
                "            <td></td>\n" +
                "            <td>" + item.checktime + "</td>\n" +
                "        </tr>\n";
        })
        $("#tableMFadd").html(str);
    })
}

function chaDF(id) {
    localStorage.setItem("WZYDfileID", id);
    location.href = "../../wen_zhi_yi/DfileXQ.html"
}

function MMADDZH() {
    let ls = [];
    $(".productid:checked").each(function () {
        ls.push(JSON.parse($(this).val()));
    })
    let lists = [];
    let tf = "";
    for (let j=0;j<ls.length;j++){
        if (j != 0) {
            if (ls[j].productid == tf) {
                tf = ls[j].productid;
                lists[j] = ls[j];
            } else {
                $("#tishi").text("选择多个生产计划派工时，必须保证产品编号一致！")
                $("#tishi").css("color", "#1ca9c4")
                $("#staticBackdrop").modal("show");
                return;
            }
        } else {
            tf = ls[j].productid;
            lists[j] = ls[j];
        }
    }

    if (lists.length>0){
        localStorage.setItem("MMADD(1)", JSON.stringify(lists));
        location.href = "../../wen_zhi_yi/mManufactureAdd(1).html";
    }
}